package com.lv.dhart.holder.cost;

import android.content.Context;
import android.view.View;

import com.lv.dhart.R;
import com.lv.dhart.beans.as4kdots.CostChangeBeans;
import com.lv.dhart.utils.UtilWidget;
import com.smart.holder.iinterface.IViewHolder;
import com.smart.holder.iinterface.IViewHolderHelper;

import java.util.List;

public class ListCostViewHolderHelper implements IViewHolderHelper<ListCostViewHolder, CostChangeBeans.DataDTO> {
    ListCostViewHolderClickListener listener;

    public void setListener(ListCostViewHolderClickListener listener) {
        this.listener = listener;
    }

    @Override
    public IViewHolder initItemViewHolder(ListCostViewHolder viewHolder, View convertView) {
        viewHolder = new ListCostViewHolder();

        viewHolder.stockCode = UtilWidget.getView(convertView, R.id.stock_code);
        viewHolder.stockName = UtilWidget.getView(convertView, R.id.stock_name);
        viewHolder.count = UtilWidget.getView(convertView, R.id.count);
        viewHolder.cost = UtilWidget.getView(convertView, R.id.cost);
        viewHolder.delete = UtilWidget.getView(convertView, R.id.delete_by_id);
        return viewHolder;
    }

    @Override
    public void bindListDataToView(Context context, List<CostChangeBeans.DataDTO> list, ListCostViewHolder listCostViewHolder, int i) {
        listCostViewHolder.cost.setText(list.get(i).getOriginCost());
        listCostViewHolder.stockCode.setText(list.get(i).getStockCode());
        listCostViewHolder.count.setText(list.get(i).getOriginCount());
        listCostViewHolder.stockName.setText(list.get(i).getStockName());
        listCostViewHolder.delete.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        listener.onDeleteClick(v, i);
                    }
                }
        );
    }
    public interface ListCostViewHolderClickListener{
        void onDeleteClick(View view, int position);
    }
}
